using System;
using System.Collections.Generic;
using System.IO;
using CommandLine;
using CommandLine.Text;

namespace BruteMerge.Merger
{
    internal class BruteMergeOptions : CommandLineOptionsBase
    {
        public BruteMergeOptions()
        {
            InputFiles = new List<string>();
        }

        private string _entryFile;

        [Option("e", "entry-file", HelpText = "Entry file of application", Required = true)]
        public string EntryFile
        {
            get { return _entryFile; }
            set { _entryFile = Path.GetFullPath(value); }
        }

        [OptionList("i", "input-files", Separator = ';', HelpText = "Input files separated with ';'")]
        public IList<string> InputFiles { get; set; }

        private string _inputDirectory;

        [Option("d", "input-directory", HelpText = "Directory with input files")]
        public string InputDirectory
        {
            get { return _inputDirectory; }
            set { _inputDirectory = value != null ? Path.GetFullPath(value) : null; }
        }

        private string _outputFile;
        
        [Option("o", "output-file", HelpText = "Output file", Required = true)]
        public string OutputFile
        {
            get { return _outputFile; }
            set { _outputFile = Path.GetFullPath(value); }
        }

        [Option(null, "inherit-icon", HelpText = "Inherit icon from original entry file")]
        public bool InheritIcon { get; set; }

        [Option(null, "inherit-version", HelpText = "Inherit version from entry original file")]
        public bool InheritVersion { get; set; }

        [Option(null, "inherit-manifest", HelpText = "Inherit manifest from entry original file")]
        public bool InheritManifest { get; set; }

        [Option(null, "console-application", HelpText = "The application is console application")]
        public bool ConsoleApplication { get; set; }

        [Option(null, "bootstrap", HelpText = "Bootstrap mode. You should not use this option")]
        public bool Bootstrap { get; set; }

        [Option(null, "debug-print", HelpText = "Enable debug output in loader")]
        public bool DebugPrint { get; set; }

        [HelpOption("?", "help")]
        public string GetUsage()
        {
            return HelpText.AutoBuild(this, current => HelpText.DefaultParsingErrorsHandler(this, current));
        }

        public static BruteMergeOptions Parse(string[] args)
        {
            var parser = new CommandLineParser(new CommandLineParserSettings(false, false, false, Console.Error));
            var options = new BruteMergeOptions();

            return parser.ParseArguments(args, options) ? options : null;
        }
    }
}